# 1.
class Restaurant(object):
    menu = {
        '土豆丝': 8,
        '剁椒鱼头': 78,
        '胡辣汤': 3,
        '羊汤': 8,
        '小葱拌豆腐': 15,
        '鱼香肉丝': 21,
        '辣子鸡丁': 43,
        '拍黄瓜': 5,
    }
    # 构造初始函数，添加属性
    # 5.
    def __init__(self, num):
        # 定义一个空的数
        self.num = num
        # 定义一个空的菜单
        self.my_menu = {}
        print(f'{num}位爷，里边请~~~')

    # 描述进入上下文的动作
    # 先执行，每个人的服务费
    # 6.
    def __enter__(self):
        self.price = self.num * 2

    # 描述推出上下文的动作
    # 后执行，从my_menu中取出菜品的价格进行相加
    # 7.
    def __exit__(self, exc_type, exc_val, exc_tb):
        print(f'总共消费{self.price + sum(self.my_menu.values())}')

    #判断有没有其他的菜在my_menu中，如果有继续进行相加运算
    # 9.
    def __add__(self, other):
        if other in self.my_menu:
            self.my_menu[other] += self.menu[other]
        else:
            self.my_menu[other] = self.menu[other]

# 和上边的Restaurant(object)对应，算是对应的人数
# 2.
r = Restaurant(6)
# 3.
# with语句，让什么语句/字段(r)执行什么命令(f)
with r as f:
    # 4.
    # 算是直接取出的菜品对应的价钱相加，将菜品放入空的字典中
    r + '小葱拌豆腐'
    r + '辣子鸡丁'
    r + '羊汤'
# 10.
print('下次再来啊！')
# i = 1
# def move(pfrom,pto):
#     global i
#     print('第%d步,%s --> %s'%(i,pfrom,pto))
#     i += 1
# def hanoi(n,a,b,c):
#     if n == 1:
#         move(a,c)
#     else:
#         hanoi(n-1,a,c,b)
#         move(a,c)
#         hanoi(n - 1,b,a,c)
# n = int(input('请输入步数:'))
# print('具体步骤如下:')
# hanoi(n,"A","B","C")
# print('一共需要走%d步'%(i-1))

# list1 = [1,2,3,4,5,6,7,8,9]
# for i in list1:
#     n = len(list1)
#     list2 = []
#     if int(i[:n]) > i[:n-1]:
#         list2.append(i)
#         print(list2)

# >= O <= 循环选中
# l1 = [1,2,5,5,5,-1,8,10]
# for w_index in range(len(l1) - 1):
#     # 当前要替换的索引
#     index = w_index
#     # 循环找到的比较数
#     for n_index in range(w_index + 1,len(l1)):
#         # 循环小于比较教
#         if l1[index] <= l1[n_index]:
#             # 更换选中数
#             index = n_index
#     else:
#         # 把选中数和外层互换
#         l1[index],l1[w_index] = l1[w_index],l1[index]
# print(l1)

from asyncio import run,sleep,ensure_future,wait,get_event_loop
# 普通的
# import time
# def task():
#     print(1)
#     time.sleep(3)
#     print(2)
# task()

# 携程
# async def task():
#     print(3)
#     await sleep(3)
#     print(5)
#
# l = [exec(f'''
#     [async def tesk{i}():
#     print(1)
#     await sleep(3)
#     print({i})
# ''')for i in range(100)]
#
# tasks = [
#     ensure_future(exec(f'task{i}()')) for i in range(100)
# ]
# loop = get_event_loop()
# loop.run_until_complete(wait(tasks))

